package com.good.shopping.search.config;

import com.good.common.constant.HostConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 整合redis作为session存储
 *
 * @author shengren.yan
 */
@Configuration
public class SessionConfig {

    /**
     * 设置session作用域为顶级域名
     *   子域名也共享session
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setDomainName(HostConstant.COM);
        cookieSerializer.setCookieName(HostConstant.COOKIENAME);
        return cookieSerializer;
    }

    // 设置序列号-使用json格式
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
//        return new GenericF();
        return new GenericJackson2JsonRedisSerializer();
    }



}
